<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Crossref extends Page
{
       public $JTDivInfo = null;
       public $JTGroupBox5 = null;
       public $Label13 = null;
       public $imgInfo = null;
       public $JTJavaScript1 = null;
       public $lbltype = null;
       public $lblname = null;
       public $lblStocknum = null;
       public $Label38 = null;
       public $lblyear = null;
       public $Label48 = null;
       public $imgBack = null;
       public $hiddenStock = null;
       public $JTSiteTheme1 = null;
       public $JTCrossRefList = null;
       public $imgAdd = null;
       public $Image1 = null;
       function imgInfoJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivInfo').Show();
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function CrossrefCreate($sender, $params)
       {
       if($_SESSION['isAdmin']!=1)
       {
       $this->imgAdd->setVisible(false);
       }
       if($_SESSION['access_part']==1)
       {
       $this->imgAdd->setVisible(false);
       }

       if($_SESSION['access_part']==2)
       {
       $this->imgAdd->setVisible(true);
       }


       $stock_id = $_GET['stock_id'];
       $this->hiddenStock->setValue($stock_id);


       $query_parts = "select * from invstocks_tbl where stock_id='".$this->hiddenStock->getValue()."'";
       $result_parts = mysql_query($query_parts)or die(mysql_error());
       $row_parts = mysql_fetch_array($result_parts);

       $this->lblStocknum->Caption = $row_parts['stock_num'];
       $this->lblname->Caption = $row_parts['description'];
       $this->lbltype->Caption = $row_parts['type'];


       $this->imgAdd->setLink('veh_parts_crossref_create.php?stock_id='.$this->hiddenStock->getValue());

       $this->imgBack->setLink('inventory_list.php?stock_id='.$this->hiddenStock->getValue());
       }

       function JTCrossRefListShow($sender, $params)
       {
       $query1 = "select * from veh_parts_crossref where stock_id='".$this->hiddenStock->getValue()."'";
       $result = mysql_query($query1)or die(mysql_error());


        $arr = array();
        while($row = mysql_fetch_array($result))
          {
            $parts_id = $row['auto'];
            $ref = $row['part_description'];

            $query_ref = "select * from invstocks_tbl where stock_id='".$ref."'";
            $result_ref = mysql_query($query_ref)or die(mysql_error());
            $row_ref = mysql_fetch_array($result_ref);



            $part = "<a href=veh_parts_crossref_edit.php?stock_id=".$this->hiddenStock->getValue()."&part=".$parts_id.">".$row_ref['part_num']."</a>";
            $tools = "<img onclick=js_deleteStock('".$this->hiddenStock->getValue()."','".$parts_id."'); src='image/delete.png' title='delete' style='cursor:pointer'>";

            //<a href=inventory_adjust_create.php?stock_id=".$stock_id."&stock_num=".$stock_num."><img src='image/status.png' title='status' no border></a>

            //if($_SESSION['isAdmin']==1)
            if($_SESSION['access_part']==2)
            {
            $arr[] = array(
                        'Part Number' => $part,
                        'Part Name' => $row_ref['description'],
                        'Manufacturer' => $row['manufacturer'],
                        'Vendor' => $row['vendor'],
                        'Tools' => $tools
                        );

            }
            //if($_SESSION['isAdmin']!=1)
            if($_SESSION['access_part']==1)
            {
            $arr[] = array(
                        'Part No.' => $part,
                        'Part Name' => $row_ref['description'],
                        'Manufacturer' => $row['manufacturer'],
                        'Vendor' => $row['vendor']
                        //'Tools' => $tools
                        );
            }





          }

            $this->JTCrossRefList->setCellData($arr);


       }

       function imgAddJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new.png"
       <?php

       }

       function imgAddJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new_blue.png"
       <?php

       }

}

global $application;

global $Crossref;

//Creates the form
$Crossref=new cROSSREF($application);

//Read from resource file
$Crossref->loadResource(__FILE__);

//Shows the form
$Crossref->show();

?>